import { Component, OnInit } from '@angular/core';
import { AuditService } from './audit.service';
import { DataService } from '../../../../../services/data.service';
import * as _ from 'lodash';
import { Util } from 'app/common/util';
@Component({
  selector: 'app-audit',
  templateUrl: './audit.component.html',
  styleUrls: ['./audit.component.scss'],
  providers: [AuditService]
})
export class AuditComponent implements OnInit {
  public item: any;

  public list: any = {
    changeMember: [],
    compareMember: [],
  }

  public display = {
    changeMember: '',
    compareMember: '',
  }
  constructor(
    public dataService: DataService,
    public auditService: AuditService
  ) { }

  ngOnInit() {
    console.log(this.list);
    this.splitDisplayData();
  }


  // 处理展示数据，加上换行符号
  splitDisplayData() {
    if(this.list.changeMember.length != 0){
      this.display.changeMember = this.list.changeMember.join('<br/>')
    }
    if(this.list.compareMember.length != 0){
      this.display.compareMember = this.list.compareMember.join('<br/>')
    }
    
    console.log(this.display.changeMember)
  }
  //审核通过
  auditPass() {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定审核通过",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          let putBody: any = {
            nFgId: that.item.nFgId,
            sType: that.item.sType,
            sFgName: that.item.sFgName,
            sFgDesc: that.item.sFgDesc,
            sFgMemberValid: that.item.sFgMemberValid,
            sMemberTemp: that.item.sMemberTemp
          }
          console.log(putBody)
          that.auditService.auditPass(putBody).subscribe(data => {
            if (data) {
              that.dataService.rcmiEditEmitter.emit('audit');
              window['swal']("成功", "完成审核", "success");
            }
          });
        }
      });
  }

  //审核不通过
  auditNotPass() {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定审核不通过",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          let putBody: any = {
            nFgId: that.item.nFgId,
            sType: that.item.sType,
            sFgName: that.item.sFgName,
            sFgDesc: that.item.sFgDesc,
            sFgMemberValid: that.item.sFgMemberValid,
            sMemberTemp: that.item.sMemberTemp,
            // sStatus: this.sStatus,
          }
          that.auditService.auditNoPass(putBody).subscribe(data => {
            if (data) {
              that.dataService.rcmiEditEmitter.emit('audit');
              window['swal']("成功", "完成审核", "success");
            }
          });
        }
      });
  }

}
